package com.example.demo.controller;

import com.example.demo.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by gf on 2018/10/13.
 */
@Controller
public class HelloController {

    @Autowired
    private Student student;

    @GetMapping(value = {"/hello/{id}","/hi/{id}"})
    public String hello(Map<String,Object> model,
                        @PathVariable(value = "id") String id){
        model.put("student",student);
        model.put("dateTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        model.put("id",id);
        return "index";
    }

    @GetMapping(value = {"/hello","/hi"})   //使此方法 同时映射多个 url访问路径
    @RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET)
    public String hello(Map<String,Object> model){
        model.put("student",student);
        return "index";
    }
}
